package com.enterprise.application.mvc.struts.interceptor;

import com.enterprise.support.utility.UserUtility;
import com.enterprise.support.utility.Validation;
import com.enterprise.support.utility.WebUtility;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * Created by IntelliJ IDEA.
 * User: Zhanggaojiang
 * Date: 11-1-19
 * Time: 上午10:14
 * Email: z82422@gmail.com
 * 用户登录 拦截器
 */
public class UserLoginInterceptor extends AbstractInterceptor {
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        if (UserUtility.isLoginUser()) {
            return actionInvocation.invoke();
        } else {
            HttpServletRequest request = WebUtility.getRequest();
            HttpSession session = request.getSession(true);
            session.setAttribute("loginredirect", request.getRequestURI() + (Validation.isEmpty(request.getQueryString()) ? "" : "?" + request.getQueryString()));
            return "global_login";
        }
    }
}
